package com.ambulance.project.biz.controller.manager;

import com.ambulance.common.utils.poi.ExcelUtil;
import com.ambulance.framework.aspectj.lang.annotation.Log;
import com.ambulance.framework.aspectj.lang.enums.BusinessType;
import com.ambulance.framework.web.controller.BaseController;
import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.framework.web.page.TableDataInfo;
import com.ambulance.project.manager.domain.BizReport;
import com.ambulance.project.manager.service.IBizReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 报告单Controller
 *
 * @author rxl
 * @date 2020-07-04
 */
@RestController
@RequestMapping("/biz/report")
public class BizReportController extends BaseController {
    @Autowired
    private IBizReportService bizReportService;

    /**
     * 查询报告单列表
     */
    //@PreAuthorize("@ss.hasPermi('biz:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizReport bizReport) {
        startPage();
        List<BizReport> list = bizReportService.selectBizReportList(bizReport);
        return getDataTable(list);
    }

    /**
     * 导出报告单列表
     */
    //@PreAuthorize("@ss.hasPermi('biz:report:export')")
    @Log(title = "报告单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizReport bizReport) {
        List<BizReport> list = bizReportService.selectBizReportList(bizReport);
        ExcelUtil<BizReport> util = new ExcelUtil<BizReport>(BizReport.class);
        return util.exportExcel(list, "report");
    }

    /**
     * 获取报告单详细信息
     */
    //@PreAuthorize("@ss.hasPermi('biz:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bizReportService.selectBizReportById(id));
    }

    /**
     * 新增报告单
     */
    //@PreAuthorize("@ss.hasPermi('biz:report:add')")
    @Log(title = "报告单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizReport bizReport) {
        return toAjax(bizReportService.insertBizReport(bizReport));
    }

    /**
     * 修改报告单
     */
    //@PreAuthorize("@ss.hasPermi('biz:report:edit')")
    @Log(title = "报告单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizReport bizReport) {
        return toAjax(bizReportService.updateBizReport(bizReport));
    }

    /**
     * 删除报告单
     */
    //@PreAuthorize("@ss.hasPermi('biz:report:remove')")
    @Log(title = "报告单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizReportService.deleteBizReportByIds(ids));
    }
}
